<?php
require_once("includes/config.php");
if (!$_SESSION['User']  || $_SESSION['User']->rid != '1')
{
	$_SESSION['User']=null;
	$smarty->assign('error',$msg_mustlogin);
	$smarty->display('tpls/index.tpl');
	die();
} 
$Security->GET_XSS();
$Security->Injection();
//
	
	//Add Company Forms Posted
	if(!empty($_POST))
	{
	
		$errors = array();
		$arname = trim($_POST["ArName"]);
		$enname = trim($_POST["EnName"]);
		$coemail = trim($_POST["CoName"]);
		
		//validate content
		if($arname!='' && $enname != '' && $coemail != '')
		{
		
			
			
			if(filter_var($coemail, FILTER_VALIDATE_EMAIL)){
				//Construct a company object
				$company = new company($arname,$enname,$coemail);
				if (!$company->AddCompany())
				{
			$smarty->assign('error',$msg_ceoemailexists);
			$company_list=getCompanyList();
			//print_r($company_list);
			$smarty->assign('company_list',$company_list);
			$content=$smarty->fetch('tpls/admin-Companies.tpl');
			$smarty->assign('content',$content);
			$smarty->display('tpls/main.tpl');
			die();
				}
				
			}else{
				echo "not valid email";
			} 
		
			
		
		}else{
			$smarty->assign('error',$msg_companyinformationmissing);
					$company_list=getCompanyList();
			//print_r($company_list);
			$smarty->assign('company_list',$company_list);
			$content=$smarty->fetch('tpls/admin-Companies.tpl');
			$smarty->assign('content',$content);
			$smarty->display('tpls/main.tpl');
			die();
			
		}
	}
	$company_list=getCompanyList();
	//print_r($company_list);
	$smarty->assign('company_list',$company_list);
	$content=$smarty->fetch('tpls/admin-Companies.tpl');
	$smarty->assign('content',$content);
	$smarty->assign('username',$_SESSION['User']->username);
	$smarty->display('tpls/main.tpl');

	
?>